Institutional Pivot Matrix Day Trading Indictor

Cut and paste this into you Think Or Swim Indicor

declare lower;

#==================================================
# 1. SCALED PPO & HISTOGRAM
#==================================================
input fastLen = 12;
input slowLen = 26;
input sigLen = 9;
input ppoVisualBoost = 500; 
input pivotLength = 5; 

def maFast = ExpAverage(close, fastLen);
def maSlow = ExpAverage(close, slowLen);
def rawPPO = 100 * (maFast - maSlow) / maSlow;

plot PPO_Line = rawPPO * ppoVisualBoost;
PPO_Line.SetDefaultColor(CreateColor(33, 150, 243)); 
PPO_Line.SetLineWeight(2);

plot Signal_Line = ExpAverage(PPO_Line, sigLen);
Signal_Line.SetDefaultColor(CreateColor(255, 109, 0)); 
Signal_Line.SetLineWeight(2);

plot Hist = PPO_Line - Signal_Line;
Hist.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Hist.SetLineWeight(3);
Hist.AssignValueColor(if Hist >= 0 then (if Hist > Hist[1] then CreateColor(38, 166, 154) else CreateColor(178, 223, 219)) else (if Hist < Hist[1] then CreateColor(255, 82, 82) else CreateColor(255, 205, 210)));

#==================================================
# 2. STRICT PIVOT DIVERGENCE DETECTION
#==================================================
def isPeak = PPO_Line == Highest(PPO_Line[-pivotLength], pivotLength + 1) and PPO_Line == Highest(PPO_Line[1], pivotLength);
def isValley = PPO_Line == Lowest(PPO_Line[-pivotLength], pivotLength + 1) and PPO_Line == Lowest(PPO_Line[1], pivotLength);

def pkPPO = if isPeak then PPO_Line else pkPPO[1];
def pkPrice = if isPeak then high else pkPrice[1];
def prevPkPPO = if isPeak then pkPPO[1] else prevPkPPO[1];
def prevPkPrice = if isPeak then pkPrice[1] else prevPkPrice[1];

def valPPO = if isValley then PPO_Line else valPPO[1];
def valPrice = if isValley then low else valPrice[1];
def prevValPPO = if isValley then valPPO[1] else prevValPPO[1];
def prevValPrice = if isValley then valPrice[1] else prevValPrice[1];

def bearDiv = isPeak and pkPrice > prevPkPrice and pkPPO < prevPkPPO;
def bullDiv = isValley and valPrice < prevValPrice and valPPO > prevValPPO;

#==================================================
# 3. VISUAL RADAR DOTS & HORIZONTAL LINES
#==================================================
# Heavy dots pinpointing the exact divergence locations
plot BearishDot = if bearDiv then PPO_Line else Double.NaN;
BearishDot.SetPaintingStrategy(PaintingStrategy.POINTS);
BearishDot.SetDefaultColor(Color.RED);
BearishDot.SetLineWeight(5);

plot BullishDot = if bullDiv then PPO_Line else Double.NaN;
BullishDot.SetPaintingStrategy(PaintingStrategy.POINTS);
BullishDot.SetDefaultColor(Color.GREEN);
BullishDot.SetLineWeight(5);

# Horizontal tracking lines to replace the diagonal drawings
plot BearishDivLevel = if bearDiv then PPO_Line else Double.NaN;
BearishDivLevel.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
BearishDivLevel.SetDefaultColor(Color.RED);
BearishDivLevel.SetLineWeight(3);

plot BullishDivLevel = if bullDiv then PPO_Line else Double.NaN;
BullishDivLevel.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
BullishDivLevel.SetDefaultColor(Color.GREEN);
BullishDivLevel.SetLineWeight(3);